package com.ts.search.controller;

import com.ts.api.manage.search.EsCourseControllerApi;
import com.ts.framework.domain.course.CoursePub;
import com.ts.framework.domain.course.TeachplanMediaPub;
import com.ts.framework.domain.search.CourseSearchParam;
import com.ts.framework.model.response.QueryResponseResult;
import com.ts.search.service.EsCourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/search/course")
public class EsCourseController implements EsCourseControllerApi {
    @Autowired
    EsCourseService esCourseService;
    /**
     * 课程搜索
     * @param page
     * @param size
     * @param courseSearchParam
     * @return
     */
    @Override
    @GetMapping("list/{page}/{size}")
    public QueryResponseResult search(@PathVariable("page") Integer page,
                                      @PathVariable("size") Integer size,
                                      CourseSearchParam courseSearchParam) {
        QueryResponseResult queryResponseResult = esCourseService.search(page, size, courseSearchParam);
        return queryResponseResult;
    }

    /**
     * 根据课程Id获取课程信息
     * @param id
     * @return
     */
    @Override
    @GetMapping("/getall/{id}")
    public Map<String, CoursePub> getAllCourseById(@PathVariable("id") String id) {
        return esCourseService.getAllCourseById(id);
    }

    /**
     * 根据课程计划查询媒资信息
     * @param teachplanId
     * @return
     */
    @Override
    @GetMapping(value="/getmedia/{teachplanId}")
    public TeachplanMediaPub getmedia(@PathVariable("teachplanId") String teachplanId) {
        return esCourseService.getmedia(teachplanId);
    }
}
